import { createBrowserRouter } from "react-router-dom";
import Layout from "@/layouts/MainLayout";
import Login from "@/pages/login";
import AuthRoute from "@/components/AuthRoute";
import Home from "../pages/home";
import ListAdd from "../pages/list/add";
import ListManage from "../pages/list/manage";
import ListFiles from "../pages/list/files";
import Upload from "../pages/upload";
import Admin from "../pages/admin";
import NotFound from "../pages/not-found";
import Forbidden from "../pages/403";

// 公开路由
export const publicRoutes = [
  {
    path: "/login",
    element: <Login />,
  },
  {
    path: "/403",
    element: <Forbidden />,
  },
  {
    path: "*",
    element: <NotFound />,
  },
];

// 需要认证的路由
export const protectedRoutes = [
  {
    path: "/",
    element: (
      <AuthRoute>
        <Layout />
      </AuthRoute>
    ),
    children: [
      {
        path: "/",
        element: <Home />,
      },
      {
        path: "/list/add",
        element: <ListAdd />,
      },
      {
        path: "/list/mange",
        element: <ListManage />,
      },
      {
        path: "/list/files",
        element: <ListFiles />,
      },
      {
        path: "/upload",
        element: <Upload />,
      },
      {
        path: "/admin",
        element: <Admin />,
      },
    ],
  },
];

// 合并所有路由
export const router = createBrowserRouter([...publicRoutes, ...protectedRoutes]);

export default router;
